import pika
import time

from utils import get_connection

connection = get_connection()
# credient = pika.PlainCredentials(username='admin', password='admin')
# connection = pika.BlockingConnection(
#     pika.ConnectionParameters(host='0.0.0.0', port=5672, virtual_host='/', credentials=credient))

channel = connection.channel()
channel.exchange_declare(exchange='direct_exchange', exchange_type='direct', durable=True)
channel.queue_declare(queue='direct_queue2', durable=True, auto_delete=True)
channel.queue_bind(exchange='direct_exchange', queue='direct_queue2', routing_key='notdirect')


def callback(channel, method, properity, body):
    # time.sleep(2)
    channel.basic_ack(delivery_tag=method.delivery_tag)
    print(body.decode())


channel.basic_qos(prefetch_count=1)
channel.basic_consume(on_message_callback=callback, queue='direct_queue1')
channel.start_consuming()
